package caseManagerBusiness;

import easyDAO.SqlDispatch;
import impl.TestServerBusinessImpl;
import models.MyConfig;
import models.ReturnJson;
import models.SqlReturnModel;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yangxianming on 2019/8/01.
 * 入职一条测试用例
 */
public class CopyCase implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        ReturnJson returnJson = new ReturnJson();
        //读取请求
        String caseId = request.getParameter("caseId");
        //数据组装
        String sqlWord = "INSERT INTO testcase (`projectName`, `caseName`, `describe`, `type`, `isdel`, `data`) ";
        sqlWord = sqlWord + "SELECT projectName, caseName, `describe`, type, isdel, `data` FROM testcase WHERE id=" + caseId;
        //INSERT INTO testcase (`projectName`, `caseName`, `describe`, `type`, `isdel`, `data`)
        //SELECT projectName, caseName, `describe`, type, isdel, `data` FROM testcase WHERE id="64"
        SqlDispatch sqlDispatch = new SqlDispatch(myConfig);
        SqlReturnModel sqlReturnModel = sqlDispatch.insert(sqlWord);
        returnJson.setApiStatus((sqlReturnModel.getIsSuccess()) ? 1 : 0);
        returnJson.setErrorMsg(sqlReturnModel.getFailingReason());
        return returnJson.toString();
    }
}
